import React, { Component } from 'react';
import {Spin} from "antd"
const asyncComponent = (loadComponent) => {
    console.log(loadComponent)
    return class extends Component{
        state={
            isLoading:true,
            loadComponent:""
        }
        componentDidMount(){
            this.loadComponent()
        }
        loadComponent(){
            if(!this.state.loadComponent){
                loadComponent().then((component)=>{
                    this.setState({
                        loadComponent:component.default,
                        isLoading:false
                    })
                    console.log(component)
                })
            }
        }
        render(){
            const PageComponent=this.state.loadComponent
            return (
                <React.Fragment>
                    <Spin spinning={this.state.isLoading}>
                    {PageComponent ? <PageComponent {...this.props}/>:""}
                    </Spin>
                </React.Fragment>
            )
        }
    }
}
export default asyncComponent;

